package com.another.bidservice.controller;

import com.another.bidservice.entity.TPlanBidder;
import com.another.bidservice.service.IPlanBidderService;
import com.another.common.utils.common.MyException;
import org.apache.log4j.Logger;
import com.another.common.utils.result.Result;
import com.another.common.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/planbidder")
@CrossOrigin
public class PlanBidderController {

    private Logger logger=Logger.getLogger(this.getClass());

    @Autowired
    private IPlanBidderService iPlanBidderService;

    @PostMapping(value = "/getList")
    @ResponseBody
    public Result getList(@RequestBody TPlanBidder tPlanBidder) {
       try {
            return iPlanBidderService.getList(tPlanBidder);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteList")
    @ResponseBody
    public Result deleteList(@RequestBody List<Integer> rowids) {
        try {
            return iPlanBidderService.deleteList(rowids);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertList")
    @ResponseBody
    public Result insertList(@RequestBody List<TPlanBidder> tPlanBidders) {
        try {
            return iPlanBidderService.insertList(tPlanBidders);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/updateList")
    @ResponseBody
    public Result updateList(@RequestBody List<TPlanBidder> tPlanBidders) {
        try {
            return iPlanBidderService.updateList(tPlanBidders);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
    
    @PostMapping(value = "/updatePlanBidder")
    @ResponseBody
    public Result updatePlanBidder(@RequestBody TPlanBidder tPlanBidder) {
        try {
            return iPlanBidderService.updatePlanBidder(tPlanBidder);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertPlanBidder")
    @ResponseBody
    public Result insertPlanBidder(@RequestBody TPlanBidder tPlanBidder) {
        try {
            return iPlanBidderService.insertPlanBidder(tPlanBidder);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deletePlanBidder")
    @ResponseBody
    public Result deletePlanBidder(@RequestBody TPlanBidder tPlanBidder) {
        try {
            return iPlanBidderService.deletePlanBidder(tPlanBidder);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
}



